package com.fancy.learncenter.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.adapter.YgtListAdapter;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.YgtListDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class YgtFreeDetailActivity extends BaseActivity {

    String classifyId = "";
    @Bind(R.id.recycleView)
    RecyclerView recycleView;


    YgtListAdapter ygtListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ygt_detail, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);

        classifyId = getIntent().getStringExtra("classifyId");
        initToolbar("项目");
        setRight("添加项目", new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(YgtFreeDetailActivity.this, YGTAddActivity.class);

                intent.putExtra("classifyId", classifyId);

                startActivity(intent);
            }

        });


        initRcycleView();

    }


    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private void initRcycleView() {
        ArrayList itemDatas = new ArrayList();
        ygtListAdapter = new YgtListAdapter(this, itemDatas, classifyId);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(linearLayoutManager);
        recycleView.setAdapter(ygtListAdapter);
    }


    private void getData() {
        HashMap maps = new HashMap();
//        maps.put("classifyId", classifyId);

        HttpMehtod.getInstance().ygtFreeDetailList(maps, new IdeaObserver<BaseDataBean>(this, true) {

            @Override
            public void onSuccess(BaseDataBean listBaseDataBean) {

                if (listBaseDataBean.getData() != null) {
                    ygtListAdapter.notifyDataSetChanged((ArrayList<YgtListDataBean>) listBaseDataBean.getData());
                } else {
                    ygtListAdapter.notifyDataSetChanged(new ArrayList<YgtListDataBean>());
                }

            }

            @Override
            public void onFail(int errorCode) {

            }

        });
    }


    @OnClick({R.id.galary_img, R.id.video_img})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.galary_img:
                intent = new Intent(this, YgtGalleryActivity.class);
                intent.putExtra("classifyId", classifyId);
                startActivity(intent);
                break;
            case R.id.video_img:
                intent = new Intent(this, YgtVideoActivity.class);
                intent.putExtra("classifyId", classifyId);
                startActivity(intent);

                break;
        }
    }
}
